package org.corey.wyp.model
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	import org.corey.wyp.vo.AccountItem;
	import org.corey.wyp.vo.Calendar;
	import org.corey.wyp.vo.Month;
	import org.corey.wyp.vo.MonthSetting;
	import org.corey.wyp.vo.ViewVo;
	
	public class Application extends EventDispatcher
	{															
		[Bindable]
		public var financeManagerViewId:String=ViewVo.TODAY_ACCOUNT;
		[Bindable]
		public var financeManagerViewTitle:String;
		[Bindable]
		public var selectedDate:String;
		
		[Bindable("todayAccountItemsChanged")]
		public var todayAccountItems:ArrayCollection=new ArrayCollection();
		
		[Bindable("monthAccontItemsChanged")]
		public var monthAccountItems:ArrayCollection=new ArrayCollection();
		
		[Bindable]
		public var currentYear:int=2010;
		
		[Bindable]
		public var currentMonth:int=3;
		
		[Bindable]
		public var currentDate:int;
		
		[Bindable]
		public var selectedSearchCalendar:Calendar=new Calendar();
		
		[Bindable]
		public var today:Calendar=new Calendar();
		
		[Bindable]
		public var curveMonth:Month;
		
		[Bindable]
		public var accountMonth:Month;
		
		[Bindable]
		public var monthSetting:MonthSetting=new MonthSetting();
		
		[Bindable]
		public var monthSettingTemplates:ArrayCollection=new ArrayCollection();
		
		[Bindable]
		public var daySettingTemplates:ArrayCollection=new ArrayCollection();
		
		
																		
		public function Application()
		{
			init();
		}
		
		private function init():void{
			
		}
		
		public function addTodayAccountItem(data:Object):void{
			today.accountItems.addItem(data);
			dispatchEvent(new Event("monthAccontItemsChanged"));
		}
		
		
		public function deleteTodayAccountItems(deleteItems:Array):void{
			for(var i:int=0;i<deleteItems.length;i++){
				var deleteItem:int=int(deleteItems[i]);
				Alert.show(deleteItem+"was deleted");
				this.deleteTodayAccountItem(int(deleteItem));
			}
			dispatchEvent(new Event("todayAccountItemsChanged"));
		}
		
		
		private function deleteTodayAccountItem(deleteItem:int):void{
			for(var i:int=0;i<today.accountItems.length;i++){
				var item:AccountItem=AccountItem(today.accountItems[i]);
				if(item.id==deleteItem){
					today.accountItems.removeItemAt(i);
				}
			}
		}
		
	}
}